//
//  H_MoreGameViewController.m
//  Honey
//
//  Created by 贾亚涵 on 16/4/9.
//  Copyright © 2016年 贾亚涵. All rights reserved.
//

#import "H_MoreGameViewController.h"
#define Start_Btn1 3001
#define Start_Btn2 3002
#define Start_Btn3 3003
@interface H_MoreGameViewController ()
{
    UIImageView * _leftBarIV;
    UIImageView * _centerBarIV;
    UILabel * _BarLabel;
    
    UILabel * _hLabel;
    UIView * _gameV1;
    UIImageView * _gameIV1;
    UILabel * _gameL1;
    UIButton * _gameBtn1;
    
    UIView * _gameV2;
    UIImageView * _gameIV2;
    UILabel * _gameL2;
    UIButton * _gameBtn2;
    
    UIView * _gameV3;
    UIImageView * _gameIV3;
    UILabel * _gameL3;
    UIButton * _gameBtn3;

}

@end

@implementation H_MoreGameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:254/255.0f green:223/255.0f blue:224/255.0f alpha:1];
    
    [self initGameView];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self infoNavigationBarBtn];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [_BarLabel removeFromSuperview];
    
    [_centerBarIV removeFromSuperview];
}


-(void)infoNavigationBarBtn
{
    _centerBarIV = [[UIImageView alloc] initWithFrame:CGRectMake(50, 10, 1, 20)];
    _centerBarIV.backgroundColor = [UIColor blackColor];
    _centerBarIV.alpha = 0.2f;
    [self.navigationController.navigationBar addSubview:_centerBarIV];
    
    _BarLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_centerBarIV.frame)+14, 10, 100, 20)];
    _BarLabel.text = @"个人游戏";
    _BarLabel.textColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:_BarLabel];
}

-(void)initGameView
{
    _hLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 64, Screen_Width, 30)];
    _hLabel.text = @"小游戏（免安装）";
    _hLabel.textColor = [UIColor grayColor];
    [self.view addSubview:_hLabel];
    
    _gameV1 = [self addUIViewWithRect:CGRectMake(0, CGRectGetMaxY(_hLabel.frame), Screen_Width, 60)];
   // [self.view addSubview:_gameV1];
    _gameIV1 = [self addUIImageViewWithImageName:@"Game1"];
    [_gameV1 addSubview:_gameIV1];
    
    _gameL1 = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_gameIV1.frame)+10, 10, 100, 40)];
    _gameL1.text = @"蜜糖拼图";
    [_gameV1 addSubview:_gameL1];
    
    _gameBtn1 = [self addUIButtonWithTag:Start_Btn1];
    [_gameV1 addSubview:_gameBtn1];
    
    
    _gameV2 = [self addUIViewWithRect:CGRectMake(0, CGRectGetMaxY(_gameV1.frame)+1, Screen_Width, 60)];
    _gameIV2 = [self addUIImageViewWithImageName:@"Game2"];
    [_gameV2 addSubview:_gameIV2];
    
    _gameL2 = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_gameIV2.frame)+10, 10, 100, 40)];
    _gameL2.text = @"蜜糖连连看";
    [_gameV2 addSubview:_gameL2];
    
    _gameBtn2 = [self addUIButtonWithTag:Start_Btn2];
    [_gameV2 addSubview:_gameBtn2];

    _gameV3 = [self addUIViewWithRect:CGRectMake(0, CGRectGetMaxY(_gameV2.frame)+1, Screen_Width, 60)];
    _gameIV3 = [self addUIImageViewWithImageName:@"Game3"];
    [_gameV3 addSubview:_gameIV3];
    
    _gameL3 = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_gameIV3.frame)+10, 10, 100, 40)];
    _gameL3.text = @"蜜糖来袭";
    [_gameV3 addSubview:_gameL3];
    
    _gameBtn3 = [self addUIButtonWithTag:Start_Btn3];
    [_gameV3 addSubview:_gameBtn3];

}

#pragma mark - UIView
-(UIView *)addUIViewWithRect:(CGRect)rect
{
    UIView * v = [[UIView alloc] initWithFrame:rect];
    v.backgroundColor = [UIColor whiteColor];
    v.userInteractionEnabled = YES;
    [self.view addSubview:v];
    return v;
}

#pragma mark- UIImageView
-(UIImageView *)addUIImageViewWithImageName:(NSString *)imageName
{
    UIImageView * ImV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
    ImV.image = [UIImage imageNamed:imageName];
    ImV.backgroundColor = [UIColor colorWithRed:252/255.0f green:135/255.0f blue:137/255.0f alpha:1];
    return ImV;
}

#pragma mark- UIButton
-(UIButton *)addUIButtonWithTag:(CGFloat)tag
{
    UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width-60, 15, 50, 30)];
    btn.backgroundColor = [UIColor orangeColor];
    [btn setTitle:@"启动" forState:UIControlStateNormal];
    btn.tag = tag;
    [btn addTarget:self action:@selector(StartBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

-(void)StartBtnClicked:(id)sender
{
    if (sender && [sender isKindOfClass:[UIButton class]]) {
        
        UIButton * STBtn =  (UIButton *)sender;
        switch (STBtn.tag) {
            case Start_Btn1:
            {
                NSLog(@"qidong1");
            }
                break;
            case Start_Btn2:
            {
                NSLog(@"qidong2");
            }
                break;
            case Start_Btn3:
            {
                NSLog(@"qidong3");
            }
                break;
            default:
                break;
        }
    }
}
@end
